package com.luli.Utils;

import org.apache.commons.lang.StringUtils;
import org.joda.time.DateTime;
import org.joda.time.format.DateTimeFormat;
import org.joda.time.format.DateTimeFormatter;

import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Arrays;
import java.util.Date;

/**
 * 陆离
 * 2022/6/7 16:46:53
 */
public class DateUtils {
    public static final String COMMON_PATTERN = "yyyy-MM-dd HH:mm:ss";
    public static final String COMMON_PATTERN_TYPE2 = "yyyy/MM/dd HH:mm:ss";
    public static final String SHORT_PATTERN = "yyyy-MM-dd";
    public static final String SHORT_PATTERN_TYPE2 = "yyyy/MM/dd";
    public static final String LONG_PATTERN = "yyyy-MM-dd HH:mm:ss.SSS";
    public static final String SUP_SHORT_PATTERN = "yyyyMMdd";
    public static final String SUP_LONG_PATTERN = "yyyyMMddHHmmss";
    public static final String YEAR_MONTH = "yyyyMM";
    public static final String CN_SHORT_PATTERN = "yyyy年MM月dd日";
    public static final String DDMM_PATTERN = "ddMM";

    public static Date trans2Date(String dateString, String pattern) {
        String fRTN = StringUtils.isNotBlank(pattern) ? pattern : COMMON_PATTERN;
        DateTimeFormatter format = DateTimeFormat.forPattern(fRTN);
        DateTime dt = DateTime.parse(dateString, format);
        return dt.toDate();
    }

    public static void main(String[] args) {
        Integer a = 0;
        String b = "";
        System.out.println(b.equals(a.toString()));
    }

    /**
     * 将String转换成Date类型
     */
    public static Date StrToDate(String str) {
        SimpleDateFormat dateFormat = new SimpleDateFormat("yyyyMMdd");
        Date parse = null;
        try {
            parse = dateFormat.parse(str);
            DateFormat dateFormat1 = new SimpleDateFormat("yyyyMMdd");
            String format = dateFormat1.format(parse);
        } catch (ParseException e) {
            e.printStackTrace();
        }

        return parse;
    }

    /**
     * 日期转换
     * 日期转yyyy-MM-dd HH:mm:ss
     *
     * @param dateTime
     */
    public static String getDateTime(String dateTime) {
        Date date = StrToDate(dateTime);
        SimpleDateFormat format = new SimpleDateFormat("yyyyMMdd");
        return format.format(date);
    }


    /**
     * 获取当前时间
     * 2022-10-25 09:42:38
     *
     * @return
     */
    public static String getAtPresent() {
        Date date = new Date();
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        format.format(date);
        return format.format(date);
    }


}
